package com.ctshk.sapp.order.custom.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.exception.BusinessException;
import com.ctshk.common.model.TokenUser;
import com.ctshk.rpc.order.custom.dto.order.*;
import com.ctshk.rpc.order.custom.req.order.*;
import com.ctshk.rpc.order.custom.req.tourist.CustomOrderTouristIdReq;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderCollectionService;
import com.ctshk.rpc.order.custom.service.ICustomizedOrderTouristInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 * 游客收款 前端控制器
 * </p>
 *
 * @author 叶冠峰
 * @since 2021-02-22
 */
@Api(value="游客收款", tags="游客收款")
@RestController
@Slf4j
@RequestMapping("/customized-order-collection")
public class CustomizedOrderCollectionController extends BaseController {

    @DubboReference
    private ICustomizedOrderCollectionService orderCollectionService;
    @DubboReference
    private ICustomizedOrderTouristInfoService orderTouristInfoService;


    @ApiOperation(value = "收款", notes = "收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-收款", operDesc = "收款管理-收款")
    @PostMapping("/add")
    public Result<CustomOrderCollectionAddDTO> add(@RequestBody @Valid CustomOrderCollectionAddReq req) {
        try {
            TokenUser currentUser = getCurrentUser(getRequest());
            return orderCollectionService.add(req,currentUser);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value="收款明细", notes="订单收款明细(叶冠峰)")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收款管理-收款明细", operDesc = "收款管理-收款明细")
    @PostMapping("/recive-list")
    public Result<List<CustomOrderTouristCollectionDTO>> reciveList(@RequestBody @Valid CustomOrderTouristIdReq req) {
        try {
            List<CustomOrderTouristCollectionDTO> dto = orderTouristInfoService.reciveList(req);
            return Result.success(dto);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "再次確認", notes = "再次確認（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "收款管理-收款明細-再次確認", operDesc = "收款管理-收款明細-再次確認")
    @PostMapping("/re-confirm")
    public Result confirm(@RequestBody @Valid CustomOrderCollectionConfirmReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.confirm(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "银行优惠计算", notes = "银行优惠计算（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-收款-银行优惠计算", operDesc = "收款管理-收款-银行优惠计算")
    @PostMapping("/calculation")
    public Result<CustomOrderCollectionCalculationDTO> calculation(@RequestBody @Valid CustomOrderCollectionCalculationReq seriesOrderCollectionCalculationReq) {
        try {
            seriesOrderCollectionCalculationReq.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.calculation(seriesOrderCollectionCalculationReq);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "调整项目", notes = "调整项目（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "收款管理-调整项目", operDesc = "收款管理-调整项目")
    @PostMapping("/adjust-project")
    public Result adjustProject(@RequestBody CustomOrderAdjustProjectReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.adjustProject(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "購買保險", notes = "購買保險（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "購買保險-購買", operDesc = "購買保險-購買")
    @PostMapping("/buy-insurance")
    public Result<OrderBuyInsuranceDTO> buyInsurance(@RequestBody @Valid CustomOrderBuyInsuranceReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.buyInsurance(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "保險收款", notes = "購買保險-保險收款（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "購買保險-保險收款", operDesc = "購買保險-保險收款")
    @PostMapping("/collect-insurance")
    public Result collectInsurance(@RequestBody CustomOrderCollectInsuranceReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.collectInsurance(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "验证优惠", notes = "验证优惠（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用优惠-驗證", operDesc = "收款管理-使用优惠-驗證")
    @PostMapping("/verify/discount")
    public Result<CustomOrderVerifyPromotionDTO> verifyDiscount(@RequestBody @Valid CustomOrderVerifyDiscountReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.verifyDiscount(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "使用优惠", notes = "使用优惠（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.OTHER, operTitle = "收款管理-使用优惠-兌換", operDesc = "收款管理-使用优惠-兌換")
    @PostMapping("/use/discount")
    public Result useDiscount(@RequestBody @Valid CustomOrderUseDiscountReq req) {
        try {
            return orderCollectionService.useDiscount(req, getCurrentUser(getRequest()));
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "可购买保险列表", notes = "可购买保险列表（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.QUERY, operTitle = "收款管理-购买保险", operDesc = "收款管理-购买保险")
    @PostMapping("/insurance-list")
    public Result<List<OrderInsuranceDTO>> insuranceList(@RequestBody @Valid CustomOrderInsuranceListReq req) {
        try {
            return orderCollectionService.insuranceList(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


    @ApiOperation(value = "审核", notes = "审核（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "审核", operDesc = "审核")
    @PostMapping("/approval")
    public Result approval(@RequestBody @Valid CustomOrderCollectionApprovalReq req) {
        try {
            req.setUserId(getCurrentUser(getRequest()).getId());
            return orderCollectionService.approval(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }

    @ApiOperation(value = "计算保险港币收款金额", notes = "保险收款-计算保险港币收款金额（叶冠峰）")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "保险收款-计算保险港币收款金额", operDesc = "保险收款-计算保险港币收款金额")
    @PostMapping("/get-hkd-amount")
    public Result getHkdAmount(@RequestBody @Valid List<GetHkdAmountReq> req) {
        try {
            return orderCollectionService.getHkdAmount(req);
        }catch (BusinessException e){
            return Result.failed(e);
        }
    }


}
